package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.gcc.bean.BannerBean;
import com.sskj.gcc.bean.GuideListBean;
import com.sskj.gcc.bean.ServiceLinkBean;
import com.sskj.gcc.http.HttpConfig;
import com.sskj.gcc.ui.fragment.HangqingFragment;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.bean.AseetListBean;
import com.sskj.gocoin.m.bean.UserInfo;
import com.sskj.lib.bean.CoinBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class HangqingFragmentPresenter extends BasePresenter<HangqingFragment> {

    public void getData() {
        httpService.getProduct(null)
                .execute(new JsonCallBack<HttpData<List<CoinBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<List<CoinBean>>> response) {
                        HttpData<List<CoinBean>> httpData = response.body();
                        if (httpData.getCode() == HttpConfig.OK) {

                            mView.updateUI(httpData.getData());
                        } else {
                            mView.finishRefresh();

                        }
                    }

                    @Override
                    public void onError(Response<HttpData<List<CoinBean>>> response) {
                        super.onError(response);
                        mView.finishRefresh();
                    }
                });
    }

    public void getBanner(String type) {
        httpService.getBanner(type)
                .execute(new JsonCallBack<HttpData<List<BannerBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<List<BannerBean>>> response) {
                        HttpData<List<BannerBean>> httpData = response.body();
                        if (httpData.getCode() == HttpConfig.OK) {

                            mView.updateBanner(httpData.getData());
                        }
                    }
                });
    }

    public void getNotice() {
        httpService.getGonggaoList("1", 3)
                .execute(new JsonCallBack<HttpData<PageBean<GuideListBean>>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<GuideListBean>>> response) {
                        HttpData<PageBean<GuideListBean>> httpData = response.body();
                        if (httpData.getCode() == HttpConfig.OK) {

                            mView.updateNotice(httpData.getData().getList());
                        }
                    }
                });
    }


    public void requestUserAssetList(boolean isFirst) {
        OkGo.<HttpData<AseetListBean>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<AseetListBean>>(this, isFirst) {

                    @Override
                    public void onSuccess(Response<HttpData<AseetListBean>> response) {
                        HttpData<AseetListBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }

    public void getUserInfo() {
        OkGo.<HttpData<UserInfo>>get(HttpConfig.BASE_URL + HttpConfig.GET_USER_INFO)
                .execute(new JsonCallBack<HttpData<UserInfo>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getCode() == 200) {
                            mView.updateUserInfo(httpData.getData());
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<UserInfo>> response) {
                        super.onError(response);
                    }
                });
    }

    /**
     * 获取资产明细
     */
    public void getAsset() {
        OkGo.<HttpData<AseetListBean>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<AseetListBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<AseetListBean>> response) {
                        HttpData<AseetListBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.refresh(httpListData.getData());
                        }
                    }
                });
    }

    //客服链接
    public void serviceLink() {
        OkGo.<HttpData<ServiceLinkBean>>post(HttpConfig.BASE_URL + HttpConfig.SERVICE_LINK)
                .execute(new JsonCallBack<HttpData<ServiceLinkBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<ServiceLinkBean>> response) {
                        HttpData<ServiceLinkBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.getServiceLink(httpListData.getData());
                        }
                    }
                });
    }

}
